<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <script src="https://cdn.jsdelivr.net/npm/vue@2.7.14/dist/vue.js"></script>
  <style>
    .wrap {
      width: 100%;
      display: flex;
      margin: 0.2rem 0 0 0;
      position: relative;
    }
    
    /*左侧的导航样式*/
    .nav_left {
      width: 21.1875rem;
      overflow: scroll;
    }
    
    .nav_left::-webkit-scrollbar {
      display: none;
    }
    
    .nav_content {
      white-space: nowrap;
      padding: 0 0.7rem;
    }
    
    .nav_content span {
      display: inline-block;
      padding: 0.4rem 0.6rem;
      font-size: 0.875rem;
    }
    
    .nav_content .active {
      border-bottom: 2px solid #7f4395;
      color: #7f4395;
    }
    
    .nav_left,
    .down {
      float: left;
    }
    
    /*右侧导航部分*/
    .down {
      flex: 1;
      display: flex;
      align-items: center;
      justify-content: center;
    }
    
    .gray {
      color: gray;
      display: inline-block;
      vertical-align: middle;
    }
  </style>
</head>
<body>
  <div id="app">
    <div>
      <span>姓名:</span>
      <input type="text" v-model="username" />
    </div>
    <div>
      <span>年龄:</span>
      <input type="number" v-model.number="age"/>
    </div>
    <div>
      <span>性别:</span>
      <select v-model="sex">
        <option value="男" name="sex" >男</option>
        <option value="女" name="sex" >女</option>
      </select>
    </div>
    <div>
      <button @click="start" >添加</button><button @click="gai" >修改</button>
    </div>
    <div>
      <table
        border="1"
        cellpadding="10"
        cellspacing="0"
      >
        <tr>
          <th>序号</th>
          <th>姓名</th>
          <th>年龄</th>
          <th>性别</th>
          <th>操作</th>
        </tr>
        <tr v-for="(item,index) in list" :key="item.id">
          <td>{{index+1}}</td>
          <td>{{item.name}}</td>
          <td>{{item.age}}</td>
          <td>{{item.sex}}</td>
          <td>
            <button @click="del(item.id)">删除</button>
            <button @click="xiu(index)">编辑</button>
          </td>
        </tr>
      </table>
    </div>
  </div>
  <script>
    const app = new Vue({
      el: '#app',
      data: {
        list:[
            {id:1,name:'高原一郎',age:18,sex:'男'},
            {id:2,name:'高原二郎',age:19,sex:'女'},
            {id:3,name:'高原斗地主',age:20,sex:'男'}
        ],
        username:'',
        age:0,
        sex:'男',

      },
      methods:{
        del(id){
          this.list=this.list.filter(item=>item.id !==id)
        },
        start(){
            let id= this.list[this.list.length + 1]
            if(this.username==='') return alert('请输入性名')
            if(this.age==='') return alert('请输入年龄')
            return this.list.push({
                id:id,
                name:this.username,
                age:this.age,
                sex:this.sex
            })
            this.username='',
            this.age=''
        },
        xiu(index){
          let editObj = this.list[index] // 把要编辑的对象信息取出来
          this.username = editObj.name
          this.age = editObj.age
          this.sex = editObj.sex
        },
       
      }
    })
  </script>
</body>
</html>